<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" trimDirectiveWhitespaces="true"%>
<%@ include file="/WEB-INF/views/include.inc.jsp"%>
<style>
	.delDefaultPermission{
		cursor:pointer;
		text-decoration: none; 
	}
	#newPermission{
		 margin-left: 15px;
   		 margin-top: 25px;
	}
	#newPermissonInput{
		margin-left:30px;
		
	}
	.adddPermissonBtn{
		cursor:pointer;
		float: right;
	    margin-right: 12px;
	    font-size: 14px;
	    font-family: 黑体;
	    color: #3C7FB1;
	    margin-bottom: 10px;
	    margin-top:-20px;
	}
</style>
<script>
	$(document).ready(function(){
		$(".delDefaultPermission").click(function(){
			$(this).parent().parent().remove();
		});
		
	});
	
	function showPermissonInput(){
		
		var flag = $("#newPermissonInput").attr('flag');
		
		if(flag=='1'){
			$("#newPermissonInput").attr('flag','0');
			$("#newPermissonInput").css('display','block');
			
			$(".adddPermissonBtn").text("隐藏");
			
		}else{
			$("#newPermissonInput").attr('flag','1');
			$("#newPermissonInput").css('display','none');
			$(".adddPermissonBtn").text("添加");
			
		}
	};
	
	function addPermisson(){
		var permName =   $("#permName").val();
		var permSn =   $("#permSn").val();
		var permDescription = $("#permDescription").val();
		if(permName=='' || permName==null ){
			alertMsg.info('权限名称不能为空！');
			return false;
		}
		if( permSn=='' || permSn==null){
			alertMsg.info('权限操作不能为空！');
			return false;
		}
		
		var parent=/^[A-Za-z]+$/;
		if(parent.test(permSn)==false)
		{
			alertMsg.info('权限操作必须是英文');
			return false;
		}
		
		var rowNum = $("#permissions_index").val();
		var returnFlag = false;
		$("input[name*='].name']").each(function(){
			if($(this).val()==permName){
				alertMsg.info('已经存在名字为'+permName+'的权限，无法添加！');
				returnFlag = true;
				return false;
			}
		});
		$("input[name*='].sn']").each(function(){
			if($(this).val()==permSn){
				alertMsg.info('已经存在名称为为'+permSn+'的权限，无法添加！');
				returnFlag = true;
				return false;
			}
		});
		
		if(returnFlag){
			return false;
		}
		
		
		var trHtml= "<tr> \
		<input type='hidden' name='permissions["+rowNum+"].name' value='"+permName+"'/> \
		<input type='hidden' name='permissions["+rowNum+"].sn' value='"+permSn+"'/> \
		<input type='hidden' name='permissions["+rowNum+"].description' value='"+permDescription+"'/> \
		<td>"+ permName +"</td> \
		<td>"+ permSn +"</td> \
		<td>"+ permDescription +"</td> \
		<td><a  class='delDefaultPermission'>删除</a></td> \
		</tr>";
		
		$("#permName").val('');
		$("#permSn").val('');
		$("#permDescription").val('');

		 $("#permissionList tbody").append(trHtml);	
		 //重新绑定删除事件
		 $(".delDefaultPermission").click(function(){
				$(this).parent().parent().remove();
			});
		 $("#permissions_index").val(Number(rowNum)+1);
	}
</script>

<div class="pageContent">
<form id="permissionForm" method="post" action="${contextPath }/module/create" class="required-validate pageForm" onsubmit="return validateCallback(this, dialogReloadRel2Module);">
	
	<div id="permissionFormContent" class="pageFormContent" layoutH="58">
		<fieldset>
		<legend>模块信息</legend>
		<p>
			<label>父模块：</label>
			<input name="parent.id" value="${module.id}" type="hidden"/>
			<input class="required" name="parent.name" type="text" readonly="readonly" value="${module.name }" class="input-medium"/>
			<a class="btnLook" href="${contextPath}/module/lookupParent" lookupGroup="parent" mask="true" title="更改父模块" width="400">查找带回</a>			
		</p>		
		<p>
			<label>名称：</label>
			<input type="text" name="name" class="input-medium validate[required,maxSize[64]] required" maxlength="64"/>
		</p>	
		<p>
			<label>优先级：</label>
			<input type="text" name="priority" class="validate[required,custom[integer],min[1],max[999]] required" value="999" maxlength="3" style="width: 80px;"/>
			<span class="info">（越小越靠前）</span>
		</p>		
		<p>
			<label>URL：</label>
			<input type="text" name="url" class="input-medium validate[required,maxSize[256]] required" maxlength="256" alt="以#、/或者http开头"/>
		</p>		
		<p>
			<label>授权名称：</label>
			<input type="text" name="sn" class="input-medium validate[required,maxSize[32]] required" maxlength="32"/>
		</p>
		<p>
			<label>模块类名：</label>
			<input type="text" name="className" class="input-medium" maxlength="256"/>
		</p>				
		<p class="nowrap">
			<label>描述：</label>
			<textarea name="description" cols="29" rows="3" maxlength="256" class="input-medium textarea-scroll"></textarea>
		</p>		
		</fieldset>
		
		
		
		
		<fieldset>
		<legend>模块权限</legend>
			<a class="adddPermissonBtn" onclick="showPermissonInput();" >添加</a>
			
			
			<div id="newPermissonInput" style="display:none" flag="1">
		
			<p>
				<label>权限名称：</label>
				<input type="text" id="permName"  maxlength="64"/>
			</p>
			<p>
				<label>操作名称：</label>
				<input type="text" id="permSn"   maxlength="32"/>
			</p>
			<p class="nowrap">
				<label>描述：</label>
				<textarea  id="permDescription"  cols="29" rows="3" maxlength="256" class="input-medium textarea-scroll"></textarea>
				<a class="button" id="newPermission" onclick="addPermisson()"><span>新增</span></a>	
			</p>
			<p>	
				
		</div>
			<input type="hidden" id="permissions_index" value="5"/>
			<table id="permissionList" style="text-align:center" class="list" width="100%">
			<thead>
				<tr>
					<th width="30%">权限名称</th>
					<th width="30%">操作名称</th>
					<th width="30%">描述</th>
					<th width="10%"></th>
				</tr>
			</thead>
			<tbody>
				
				<tr>
					<input type="hidden" name="permissions[0].name" value="菜单"/>
					<input type="hidden" name="permissions[0].sn" value="show"/>
					<input type="hidden" name="permissions[0].description" value="单显示权限"/>
					<td>菜单</td>
					<td>show</td>
					<td>菜单显示权限</td>
					<td><a class="delDefaultPermission">删除</a></td>
				</tr>
				<tr>
					<input type="hidden" name="permissions[1].name" value="新增"/>
					<input type="hidden" name="permissions[1].sn" value="create"/>
					<input type="hidden" name="permissions[1].description" value="新增"/>
					<td>新增</td>
					<td>create</td>
					<td>新增</td>
					<td><a class="delDefaultPermission">删除</a></td>
				</tr>
				<tr>
					<input type="hidden" name="permissions[2].name" value="删除"/>
					<input type="hidden" name="permissions[2].sn" value="delete"/>
					<input type="hidden" name="permissions[2].description" value="删除"/>
					<td>删除</td>
					<td>delete</td>
					<td>删除</td>
					<td><a class="delDefaultPermission">删除</a></td>
				</tr>
				<tr>
					<input type="hidden" name="permissions[3].name" value="修改"/>
					<input type="hidden" name="permissions[3].sn" value="edit"/>
					<input type="hidden" name="permissions[3].description" value="修改"/>
					<td>修改</td>
					<td>edit</td>
					<td>修改</td>
					<td><a class="delDefaultPermission">删除</a></td>
				</tr>
				<tr>
					<input type="hidden" name="permissions[4].name" value="查看"/>
					<input type="hidden" name="permissions[4].sn" value="view"/>
					<input type="hidden" name="permissions[4].description" value="查看"/>
					<td>查看</td>
					<td>view</td>
					<td>查看</td>
					<td><a  class="delDefaultPermission">删除</a></td>
				</tr>
				
			</tbody>
			</table>	
				
		</fieldset>
		
		
		
	</div>
			
	<div class="formBar">
		<ul>
			<li><div class="button"><div class="buttonContent"><button type="submit">确定</button></div></div></li>
			<li><div class="button"><div class="buttonContent"><button type="button" class="close">关闭</button></div></div></li>
		</ul>
	</div>
</form>
</div>